﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


namespace EHTWebsite.Code
{
    /// <summary>
    /// Summary description for HoTroProvider
    /// CuongBH
    /// 07/12/2011
    /// </summary>
    public class HoTroProvider
    {
        public static void IUHoTro(HoTro theHoTro, bool IsAdd)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_IUHoTros";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@HoTroID", theHoTro.HoTroID));
            command.Parameters.Add(new SqlParameter("@GhiChuVN", theHoTro.GhiChuVN));           
            command.Parameters.Add(new SqlParameter("@Skype", theHoTro.Skype));
            command.Parameters.Add(new SqlParameter("@Yahoo", theHoTro.Yahoo));
            command.Parameters.Add(new SqlParameter("@Gtalk", theHoTro.Gtalk));
            command.Parameters.Add(new SqlParameter("@Phone", theHoTro.Phone));
            command.Parameters.Add(new SqlParameter("@Hotline", theHoTro.Hotline));
            command.Parameters.Add(new SqlParameter("@Room", theHoTro.Room));            
            command.Parameters.Add(new SqlParameter("@IsAdd", IsAdd));

            DataProvider.ExecuteNoneQuery(command);
        }

        public static void DeleteHoTroByHoTroID(Int32 HoTroID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_DeleteHoTroByHoTroID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@HoTroID", HoTroID));

            DataProvider.ExecuteNoneQuery(command);
        }

        public static DataSet GetHoTros()
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetHoTros";
            command.CommandType = CommandType.StoredProcedure;

            return DataProvider.ExecuteDataSet(command);
        }

        public static HoTro GetHoTroByHoTroID(Int32 HoTroID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetHoTroByHoTroID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@HoTroID", HoTroID));

            DataSet ds = DataProvider.ExecuteDataSet(command);
            HoTro theHoTro = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                theHoTro = new HoTro();
                theHoTro.GhiChuVN = ds.Tables[0].Rows[0]["GhiChuVN"].ToString();
                theHoTro.GhiChuOther = ds.Tables[0].Rows[0]["GhiChuOther"].ToString();
                theHoTro.Skype = ds.Tables[0].Rows[0]["Skype"].ToString();
                theHoTro.Yahoo = ds.Tables[0].Rows[0]["Yahoo"].ToString();
                theHoTro.Gtalk = ds.Tables[0].Rows[0]["Gtalk"].ToString();
                theHoTro.Phone = ds.Tables[0].Rows[0]["Phone"].ToString();
                theHoTro.Hotline = ds.Tables[0].Rows[0]["Hotline"].ToString();
                theHoTro.HoTroID = Int32.Parse(ds.Tables[0].Rows[0]["HoTroID"].ToString());
            }

            return theHoTro;
        }

        public static void ChangePublish(Int32 HoTroID, Boolean TrangThai)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "[proc_ChangePublishByHoTroID]";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@HoTroID", HoTroID));
            command.Parameters.Add(new SqlParameter("@Publish", TrangThai));
            DataProvider.ExecuteNoneQuery(command);
        }
    }
}